package com.duan.service;

import com.duan.mapper.AwardMapper;
import com.duan.mapper.SettingMapper;
import com.duan.pojo.Award;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AwardService {
    private final AwardMapper awardMapper;
    private final SettingMapper settingMapper;

    @Autowired
    public AwardService(AwardMapper awardMapper, SettingMapper settingMapper){
        this.awardMapper = awardMapper;
        this.settingMapper = settingMapper;
    }

    /***
     * 查找此次抽奖设置的所有奖项种类
     * @param settingId settingId：设置编号
     * @return 此次抽奖设置的所有奖项种类
     */
    public List<Award> queryBySettingId(Integer settingId){
        return awardMapper.selectAwardsBySettingId(settingId);
    }


    /***
     * 增加新的奖项
     * @param award 接收前端传来信息封装成的award对象
     * @param userId currentUser的id
     * @return insert操作改变的行数
     */
    public int add(Award award, Integer userId){
        //通过userId找到settingId
        Integer settingId = settingMapper.queryIdByUserId(userId);
        //设置award中settingId属性
        award.setSettingId(settingId);
        //插入一条award数据/对象
        return awardMapper.insertSelective(award);
    }

    //更新
    public int update(Award award){
        return awardMapper.updateByPrimaryKeySelective(award);
    }

    //删除
    public int delete(int awardId){
        return awardMapper.deleteByPrimaryKey(awardId);
    }



}
